import React, { useEffect } from "react";
import { useDidShow, useDidHide } from "@tarojs/taro";
import "taro-ui/dist/style/index.scss"; // 全局引入一次即可
// 全局样式
import "./app.less";
import { useLaunch } from "@tarojs/taro";
import Taro from "@tarojs/taro";
import { ConfigProvider } from "@nutui/nutui-react-taro";
import { getPlatformConfigApi } from "./servers/servers";

function App(props) {
  // 可以使用所有的 React Hooks
  useEffect(() => {});

  // 对应 onShow
  useDidShow(async () => {
    const _res = await getPlatformConfigApi();

    console.log("_res", _res);
    Taro.setStorageSync("plat_token", _res?.data?.token);
  });

  // 对应 onHide
  useDidHide(() => {});

  // onLaunch
  useLaunch(() => {
    const _token = Taro.getStorageSync("token");
    if (_token) {
      Taro.switchTab({
        url: "/pages/index/index",
      });
    }
  });

  const darkTheme = {
    nutuiColorPrimary: "green",
    nutuiColorPrimaryStop1: "green",
    nutuiColorPrimaryStop2: "green",
  };

  return <ConfigProvider theme={darkTheme}>{props.children}</ConfigProvider>;
}

export default App;
